from langchain_core.embeddings import Embeddings
import httpx

class DeepSeekEmbeddings(Embeddings):
    def __init__(self):
        self.api_key = envConfig.DEEPSEEK_API_KEY
        self.base_url = envConfig.DEEPSEEK_BASE_URL

    def embed_query(self, text: str) -> list[float]:
        headers = {
            "Authorization": f"Bearer {self.api_key}",
            "Content-Type": "application/json"
        }
        data = {
            "input": text,
            "model": "deepseek-embedding"  # 根据实际模型名称调整
        }
        response = httpx.post(
            f"{self.base_url}/embeddings",
            headers=headers,
            json=data
        )
        return response.json()['data'][0]['embedding']

    def embed_documents(self, texts: list[str]) -> list[list[float]]:
        return [self.embed_query(text) for text in texts]